home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / 3d_tools / irit40s.lha / Irit / grapdrvs / drawpoly.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-30  |  2.9 KB  |  114 lines

  1. /*****************************************************************************
  2. *   Default polyline/gon drawing routine common to graphics drivers.         *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "iritprsr.h"
  9. #include "cagd_lib.h"
  10. #include "iritgrap.h"
  11.  
  12. /****************************************************************************
  13. * Draw a Poly object using current modes and transformations.            *
  14. ****************************************************************************/
  15. void IGDrawPoly(IPObjectStruct *PObj)
  16. {
  17.     IPVertexStruct *V;
  18.     IPPolygonStruct
  19.     *Pl = PObj -> U.Pl;
  20.  
  21.     IGSetColorObj(PObj);
  22.  
  23.     if (IGGlblAbortKeyPressed)
  24.     return;
  25.  
  26.     if (IP_IS_POLYLINE_OBJ(PObj)) {
  27.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  28.         if (Pl -> PVertex != NULL && Pl -> PVertex -> Pnext != NULL) {
  29.         IGMoveTo3D(Pl -> PVertex -> Coord);
  30.         for (V = Pl -> PVertex -> Pnext; V != NULL; V = V -> Pnext)
  31.             IGLineTo3D(V -> Coord);
  32.         }
  33.     }
  34.     }
  35.     else if (IP_IS_POINTLIST_OBJ(PObj)) {
  36.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  37.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  38.         int i;
  39.         PointType Ends[6];
  40.         RealType
  41.             *Pt = V -> Coord;
  42.  
  43.         for (i = 0; i < 6; i++)
  44.             PT_COPY(Ends[i], Pt);
  45.  
  46.         Ends[0][0] -= IG_POINT_WIDTH;
  47.         Ends[1][0] += IG_POINT_WIDTH;
  48.         Ends[2][1] -= IG_POINT_WIDTH;
  49.         Ends[3][1] += IG_POINT_WIDTH;
  50.         Ends[4][2] -= IG_POINT_WIDTH;
  51.         Ends[5][2] += IG_POINT_WIDTH;
  52.  
  53.         for (i = 0; i < 6; i += 2) {
  54.             IGMoveTo3D(Ends[i]);
  55.             IGLineTo3D(Ends[i+1]);
  56.         }
  57.         }
  58.     }
  59.     }
  60.     else if (IP_IS_POLYGON_OBJ(PObj)) {
  61.     int i, j,
  62.         NumOfVertices;
  63.     PointType PNormal, VNormal;
  64.  
  65.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  66.         IPVertexStruct *PrevV;
  67.  
  68.         if (IGGlblDrawPNormal) {
  69.         NumOfVertices = 0;
  70.         PNormal[0] = PNormal[1] = PNormal[2] = 0.0;
  71.         }
  72.  
  73.         IGMoveTo3D(Pl -> PVertex -> Coord);
  74.         for (PrevV = Pl -> PVertex, V = PrevV -> Pnext;
  75.          V != NULL;
  76.          PrevV = V, V = V -> Pnext) {
  77.         if (IP_IS_INTERNAL_VRTX(PrevV) && !IGGlblDrawInternal)
  78.             IGMoveTo3D(V -> Coord);
  79.         else
  80.             IGLineTo3D(V -> Coord);
  81.  
  82.         if (IGGlblDrawPNormal) {
  83.             for (j = 0; j < 3; j++)
  84.             PNormal[j] += V -> Coord[j];
  85.             NumOfVertices++;
  86.         }
  87.         }
  88.         if (!IP_IS_INTERNAL_VRTX(PrevV) || IGGlblDrawInternal)
  89.         IGLineTo3D(Pl -> PVertex -> Coord);
  90.  
  91.         if (IGGlblDrawPNormal && IP_HAS_PLANE_POLY(Pl)) {
  92.         for (i = 0; i < 3; i++)
  93.             PNormal[i] /= NumOfVertices;
  94.         IGMoveTo3D(PNormal);
  95.         for (i = 0; i < 3; i++)
  96.             PNormal[i] += Pl -> Plane[i] * IGGlblNormalLen;
  97.         IGLineTo3D(PNormal);
  98.         }
  99.  
  100.         if (IGGlblDrawVNormal) {
  101.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  102.             if (IP_HAS_NORMAL_VRTX(V)) {
  103.             for (j = 0; j < 3; j++)
  104.                 VNormal[j] = V -> Coord[j] +
  105.                          V -> Normal[j] * IGGlblNormalLen;
  106.             IGMoveTo3D(V ->Coord);
  107.             IGLineTo3D(VNormal);
  108.             }
  109.         }
  110.         }
  111.     }
  112.     }
  113. }
  114.